<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../../Themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../../Themes/icon.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/demo.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/common.css">
	</head>
	<style type="text/css">
		#fm {
			text-align: center;
		}
	</style>

	<body style="padding: 0px;">
		<div id="toolbar" class="receipts_toolbar_style"></div>
		<div class="easyui-layout" style="width:100%;height:550px;">
			<div id="div_search" data-options="region:'north'" style="height:120px;"></div>
			<div data-options="region:'center'">
				<div id="p" class="easyui-panel" style="width:100%;height:100%;padding:0px;">
					<div>
						<table id="dg" style="width: 100%;" class="table_style">
						</table>
					</div>
				</div>
			</div>
		</div>
		<div id="div_dialog" class="easyui-dialog" closed="true" style="width: 400px;height: 420px;padding: 20px 20px;">
			<form id="fm" method="post"></form>
		</div>
	</body>
	<script type="text/javascript" src="../../../JS/jquery.min.js"></script>
	<script type="text/javascript" src="../../../JS/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../../../JS/common.js"></script>
	<script type="text/javascript" src="../../../JS/buildDialogSearch.js"></script>
	<script type="text/javascript">
		$(document).ready(function() {
			initCombobox();
		});

		var globelOption = '';

		var searchType = SEARCH_CUSTOMER_TYPE + SEARCH_CUSTOMER_NAME + SEARCH_INTERNAL_TYPE;
		searchType += SEARCH_INTERNAL_NAME + SEARCH_CREATE_MAN + SEARCH_ORDER_NO;
		searchType += SEARCH_DISTRIBUTION_DATE_START + SEARCH_DISTRIBUTION_DATE_END;
		$("#div_search").append(constructSearchOptionFormat(searchType, ""));
		var content = buildSearchOptions(searchType, "");
		$("#fm").append(content);
		content = AddReceiptsToolBar(1152, ""); /**根据用户的权限，来决定生成ToolBar的哪些功能**/
		$("#toolbar").append(content); /*在ID=toolbar的标记后面添加content中的内容*/
		$('#dg').datagrid({
			// url: RemoteLinkAddress + '/logistics/salesorder/findbydetail.do',
			method: 'get',
			rownumbers: 'true',
			pagination: 'true',
			autoRowHeight: 'true',
			fitColumns: 'false',
			singleSelect: 'true',
			height: 350,
			/*表格中的列名以及各自列名的ID*/
			columns: [
				[{
					field: 'ORDER_NO',
					title: '销售单号',
					width: '13%',
					align: 'center'
				}, {
					field: 'CUSTOMER_TYPE',
					title: '用户组',
					width: '13%',
					align: 'center'
				}, {
					field: 'CUSTOMER_NAME',
					title: '配送单位',
					width: '13%',
					align: 'center'
				}, {
					field: 'DISTRIBUTION_DATE',
					title: '配送时间',
					width: '13%',
					align: 'center'
				}, {
					field: 'INTERNAL_TYPE',
					title: '商品类型',
					width: '13%',
					align: 'center',
				}, {
					field: 'INTERNAL_NAME',
					title: '商品名称',
					width: '13%',
					align: 'center',
				}, {
					field: 'CREATE_MAN',
					title: '制单人',
					width: '13%',
					align: 'center',
				}]
			],
			onDblClickRow: function(index, row) {
				var pLocation = "";
				pLocation = "UI/LOGISTICS/SellOrder/SellOrderAdd.html?id=" + row.ID;
				AddTabIn("销售订单详情", parent.$("#tabs"), pLocation);
			},
		});
		$("#div_dialog").dialog({
			title: "查询",
			width: 400,
			height: 420,
		});

		function initCombobox() {
			//商品类型
			$('#search_internal_type').combobox({
				valueField: 'INTERNAL_TYPE',
				textField: 'INTERNAL_TYPE',
				panelHeight: 200,
				mode: 'remote',
				method: 'get',
				editable: false,
				url: RemoteLinkAddress + "/logistics/internaltradetype/listall.do",
			});
			$('#search_customer_type').combobox({
				valueField: 'CUSTOMER_TYPE',
				textField: 'CUSTOMER_TYPE',
				panelHeight: 200,
				mode: 'remote',
				method: 'get',
				editable: false,
				url: RemoteLinkAddress + "/logistics/customertype/listall.do",
				onSelect: function(record) {
					var _url = "";
					_url = RemoteLinkAddress + '/logistics/customer/listall.do?CUSTOMER_TYPE=' + record.CUSTOMER_TYPE;
					$('#search_customr_name').combobox("reload", _url);
				}
			});
			$('#search_customr_name').combobox({
				valueField: 'CUSTOMER_NAME',
				textField: 'CUSTOMER_NAME',
				panelHeight: 200,
				mode: 'remote',
				method: 'get',
				url: RemoteLinkAddress + '/logistics/customer/listall.do',
				onChange: function(newValue, oldValue) {
					if(newValue != "" && newValue != undefined) {
						var url = RemoteLinkAddress + "/logistics/customer/findbypinyin?PINYINFIELDNAME=" + newValue.trim();
						$(this).combobox("reload", url);
					}
				}
			});
			$('#search_commodity_name').combobox({
				valueField: 'INTERNAL_NAME',
				textField: 'INTERNAL_NAME',
				panelHeight: 200,
				mode: 'remote',
				method: 'get',
				url: RemoteLinkAddress + '/logistics/internaltrade/listall.do',
				onChange: function(newValue, oldValue) {
					if(newValue != "" && newValue != undefined) {
						var url = RemoteLinkAddress + "/logistics/internaltrade/findbypinyin?PINYINFIELDNAME=" + newValue.trim();
						$(this).combobox("reload", url);
					}
				}
			});
		}

		function searchmore() {
			$('#div_dialog').dialog('open').dialog('center').dialog('setTitle', '查询');
			$('#fm').form('clear');
			$('#ff').form('clear');
		}

		function doSearch() {
			$("#div_dialog").dialog('close');
			var searchCondition = processSearchCondition(true);
			var _url = RemoteLinkAddress + '/logistics/salesorder/findbydetail.do?' + searchCondition;
			globelOption = searchCondition;
			getRemoteData(_url);
		}
		function getRemoteData(_url) {
			$.ajax({
				type: "get",
				url: _url,
				dataType: 'json',
				success: function(result) {
					$('#dg').datagrid('loadData', result.rows);
				},
				error: function(error) {

				}
			});
		}

		//导出
		function exportExcel(){
			var _url = RemoteLinkAddress + '/logistics/salesorder/findbydetail/excel.do'
			if(globelOption.length > 0){
				_url += '?' + globelOption;
			}
			$.messager.confirm("提示", "确认导出Excel表格吗？", function(r) {
				if(r) {
				$.ajax({ //调用ajax方法，从服务器获取到该订单的所有数据
					type: "get",
					dataType: "json", //服务器返回的数据类型
					url: _url,
					success: function(result) {
						window.location.href = result.path;
					}, //请求成功后，接受服务器传来的Json字符串，并做相应的处理
					error: function(xhr, status, error) {
						$.messager.alert("错误", "请求失败!");
						}
					});
				}
			});
		}

		function closeForm() {
			$("#div_dialog").dialog('close');
		}

	</script>

</html>